define([
    "jquery",
    "IO",
    "UPLOADUI",
    "UPLOAD",
    "jqueryUI",
    "bootbox"
], function($,IO, upui, up, jui,bootbox) {
    $('#fileupload').fileupload({
        url: '/upload',
        dataType: 'json',
        autoUpload: true,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        maxFileSize: 10000000, // 10 MB
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        previewMaxWidth: 150,
        previewMaxHeight: 150,
        previewCrop: true
    }).on('fileuploadadd', function (e, data) {
        document.getElementById('upimgs').src = '/images/loading.gif';

    }).on('fileuploadprocessalways', function (e, data) {
        //console.log("fileuploadprocessalways",data);
    }).on('fileuploadprogressall', function (e, data) {
        //console.log("fileuploadprogressall",data);
    }).on('fileuploaddone', function (e, data) {
        //alert('Img'+youpaiImg);
        //alert(data._response.result.url);
        //document.getElementById('upimgs').src = data._response.result.url;
        //console.log(youpaiImg);
        //  console.log("fileuploaddone",data);
        var alt = $(e.target).attr('alt');
        if (!alt)
            alt = '';
        console.log("#upimgs" + alt);
        $("#upimgs" + alt).attr("src", data._response.result.url);
    });

    //修改题目
    $(document).on("click",".publish",function(){
        var course_id = $("#course_id").val();
        console.log("---------------------------------------------------------::"+course_id)
        var course_name = $("#course_name").val();
        var course_desc = editor.html();
        var sequence = $("#sequence").val();
        var cover = $("#upimgs").attr("src");
        var teacher_name = $("#teacher_name").val();
        var major_id = $("#major_name option:selected").attr("data-id");
        var major_name = $("#major_name option:selected").val();

        var param = {};
        param.major_id = major_id;
        param.major_name = major_name;
        if(cover){
            param.cover = cover;
        }else{
            alert("请上传图片~");
            return;
        }
        if(course_id){
            param.course_name = course_name;
            param.course_id = course_id;
        }else{
            alert("请填写课程名称~");
            return;
        }
        if(sequence){
            param.sequence = sequence;
        }else{
            alert("请填写课程编号~");
            return;
        }
        if(teacher_name){
            param.teacher_name = teacher_name;
        }else{
            alert("请填写老师姓名~");
            return;
        }
        if(course_name){
            param.course_name = course_name;
        }else{
            alert("请选择专业名称~");
            return;
        }
        if(course_desc){
            param.course_desc = course_desc;
        }else{
            alert("请填写课程详情~");
            return;
        }

        if(param){
            bootbox.confirm("确定要修改该题目？",function(result){
                if(result) {
                    IO.post("act/editcourse",param,function(d){
                        bootbox.alert(d.msg,function(){
                            if (d.code == 0) {
                                location.href = '/pte/course';
                            }
                        })
                    });
                }
            });
        }
    });


});
